<?php
namespace RH\Mountains\Domain\Model;

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2014 
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 *
 *
 * @package mountains
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
 *
 */
class Mountain extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {

	/**
	 * groupe d'altitude
	 *
	 * @var \integer
	 */
	protected $groupAltitude;

	/**
	 * url du drapeau
	 *
	 * @var \string
	 */
	protected $firstFlag;

	/**
	 * nom du pays
	 *
	 * @var \string
	 */
	protected $firstCountryName;

	/**
	 * url de la photo sur le sommet
	 *
	 * @var \string
	 */
	protected $victoryPicture;

	/**
	 * name
	 *
	 * @var \string
	 */
	protected $name;

	/**
	 * altitude
	 *
	 * @var \integer
	 */
	protected $altitude;

	/**
	 * data
	 *
	 * @var \string
	 */
	protected $data;

	/**
	 * style
	 *
	 * @var \integer
	 */
	protected $style;

	/**
	 * done
	 *
	 * @var \DateTime
	 */
	protected $done;

	/**
	 * position
	 *
	 * @var \RH\Mountains\Domain\Model\Position
	 */
	protected $position;

	/**
	 * country
	 *
	 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SJBR\StaticInfoTables\Domain\Model\Country>
	 */
	protected $country;

	/**
	 * __construct
	 *
	 * @return Mountain
	 */
	public function __construct() {
		//Do not remove the next line: It would break the functionality
		$this->initStorageObjects();
	}

	/**
	 * Initializes all ObjectStorage properties.
	 *
	 * @return void
	 */
	protected function initStorageObjects() {
		/**
		 * Do not modify this method!
		 * It will be rewritten on each save in the extension builder
		 * You may modify the constructor of this class instead
		 */
		$this->country = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
	}

	/**
	 * Returns the first Flag url
	 *
	 * @return \string $firstFlag
	 */
	public function getFirstFlag() {
		$countries = $this->getCountry();
		// \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('first flag', 'model mountain', 1, 
			// array($countries->current(), '', $countries));
		$this->firstFlag = ($countries->count() > 0) ? 'EXT:mountains/Resources/Public/Images/Flags/' . $countries->current()->getIsoCodeA2() . '.png' : '';
		return $this->firstFlag;
	}

	/**
	 * Returns the first country name
	 *
	 * @return \string $firstCountryName
	 */
	public function getFirstCountryName() {
		$countries = $this->getCountry();
		$this->firstCountryName = ($countries->count() > 0) ? $countries->current()->getNameLocalized() : '';
		return $this->firstCountryName;
	}

	/**
	 * Returns the name
	 *
	 * @return \string $name
	 */
	public function getName() {
		return $this->name;
	}

	/**
	 * Sets the name
	 *
	 * @param \string $name
	 * @return void
	 */
	public function setName($name) {
		$this->name = $name;
	}

	/**
	 * Returns the altitude
	 *
	 * @return \integer $altitude
	 */
	public function getAltitude() {
		return $this->altitude;
	}

	/**
	 * Sets the altitude
	 *
	 * @param \integer $altitude
	 * @return void
	 */
	public function setAltitude($altitude) {
		$this->altitude = $altitude;
	}

	/**
	 * Returns the data
	 *
	 * @return \string $data
	 */
	public function getData() {
		return $this->data;
	}

	/**
	 * Sets the data
	 *
	 * @param \string $data
	 * @return void
	 */
	public function setData($data) {
		$this->data = $data;
	}

	/**
	 * Returns the style
	 *
	 * @return \integer $style
	 */
	public function getStyle() {
		return $this->style;
	}

	/**
	 * Sets the style
	 *
	 * @param \integer $style
	 * @return void
	 */
	public function setStyle($style) {
		$this->style = $style;
	}

	/**
	 * Returns the group Altitude
	 *
	 * @return \integer $groupAltitude
	 */
	public function getGroupAltitude() {
		$this->groupAltitude = floor($this->getAltitude() / 1000);
		return $this->groupAltitude;
	}
	
	/**
	 * Returns the done
	 *
	 * @return \DateTime $done
	 */
	public function getDone() {
		return $this->done;
	}

	/**
	 * Sets the done
	 *
	 * @param \DateTime $done
	 * @return void
	 */
	public function setDone($done) {
		$this->done = $done;
	}

	/**
	 * Returns the position
	 *
	 * @return \RH\Mountains\Domain\Model\Position $position
	 */
	public function getPosition() {
		return $this->position;
	}

	/**
	 * Sets the position
	 *
	 * @param \RH\Mountains\Domain\Model\Position $position
	 * @return void
	 */
	public function setPosition(\RH\Mountains\Domain\Model\Position $position) {
		$this->position = $position;
	}

	/**
	 * Adds a Country
	 *
	 * @param \SJBR\StaticInfoTables\Domain\Model\Country $country
	 * @return void
	 */
	public function addCountry(\SJBR\StaticInfoTables\Domain\Model\Country $country) {
		$this->country->attach($country);
	}

	/**
	 * Removes a Country
	 *
	 * @param \SJBR\StaticInfoTables\Domain\Model\Country $countryToRemove The Country to be removed
	 * @return void
	 */
	public function removeCountry(\SJBR\StaticInfoTables\Domain\Model\Country $countryToRemove) {
		$this->country->detach($countryToRemove);
	}

	/**
	 * Returns the country
	 *
	 * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SJBR\StaticInfoTables\Domain\Model\Country> $country
	 */
	public function getCountry() {
		return $this->country;
	}

	/**
	 * Sets the country
	 *
	 * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\SJBR\StaticInfoTables\Domain\Model\Country> $country
	 * @return void
	 */
	public function setCountry(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $country) {
		$this->country = $country;
	}

}
?>